package core.mode;

import java.util.Iterator;
import java.util.Random;

import view.renderer.EntityRenderer;
import view.renderer.FPSRenderer;
import view.renderer.TerrainRenderer;
import core.input.TestModeKeyListener;
import data.GameData;
import data.TempFrameData;
import data.entity.Entity;
import data.entity.monster.Monster;

public class TestMode extends Mode {

	private Random r;
	
	public TestMode(GameData d, TerrainRenderer t, FPSRenderer fps,
			EntityRenderer e) {
		super(d, new TestModeKeyListener(d.getPlayer()));
		renderers.add(t);
		renderers.add(fps);
		renderers.add(e);
		r = new Random(System.currentTimeMillis());
	}

	@Override
	public void update(TempFrameData temp) {
		super.update(temp);
		if(data.getEntities().size() < 10){
		Monster mon = data.getEntityFactory().getNewMonster();
		mon.getRectangle().x = r.nextInt(700);
		mon.getRectangle().y = r.nextInt(1000);
		data.addEntity(mon);
		}
		long delta = temp.delta;
		Iterator<Entity> it = data.getEntities().iterator();
		while(it.hasNext()){
			Entity e = it.next();
			if(e instanceof Monster){
				int direction = r.nextInt(4);
				switch(direction){
				case 0: e.moveLeft(delta); break;
				case 1: e.moveTop(delta); break;
				case 2: e.moveRight(delta); break; 
				case 3: e.moveBot(delta); break;
				default:break;
				}
			}
		}
	}

}
